package com.yuhao.common.strcount;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;

public class Main1 {

    public static void main(String[] args) {
        /**第一组*/
         String[] strs = {"\"ZW_WYJRQ\"",
         "\"ZW_WYJJJR\"",
         "\"FW_TDTZJL\"",
         "\"FW_YYT\"",
         "\"FW_XXFBSQ\"",
         "\"FW_ZSDA\"",
         "\"FW_ZSDSQXX\"",
         "\"FW_ZSFL\"",
         "\"FW_ZSD\"",
         "\"FW_ZSWT\"",
         "\"FW_ZSDGL\"",
         "\"FW_TDKHMX\"",
         "\"FW_TDTZPGXX\"",
         "\"FW_TDSB\"",
         "\"FW_TDSJ\"",
         "\"FW_TDJH\"",
         "\"FW_TFDGDXX\""
         };
        /** 第二组
        String[] strs = {
                "\"HS_DFTZDMXXX\"",
                "\"ZW_PJDYXX\"",
                "\"ZW_QFJL\"",
                "\"ZW_QFMX\"",
                "\"ZW_WYJMX\"",
                "\"HS_DFTZRZ\"",
                "\"HS_LJFMX\"",
                "\"LC_CBXX\"",
                "\"ZW_YSJH\"",
                "\"ZW_YSJL\"",
                "\"ZW_YGDCZXX\""
        };*/
        /** 第三组
        String[] strs = {
                "\"ZW_SSDFJL\"",
                "\"ZW_SSDFMX\"",
                "\"ZW_YSDFJL\"",
                "\"ZW_YSDFMX\""
        };*/
        List<String> list = toArrayByFileReader1("D:\\数据迁移日志/客服中心源表组2导出日志.log");
        Map<String, String> map = new HashMap<>();
//        DecimalFormat decimalFormat =  new DecimalFormat ("#.0000");
        for (String str : strs) {
            for (int i = 0; i < list.size(); i++) {
                String e = list.get(i);
                if (e.indexOf(str) != -1) {
                    String result = subStrAreacode(e, ":\"", "\"");
                    map.put(result, str);
                }
            }
        }

        List<String> lists = new ArrayList<>();
        for (Map.Entry<String, String> m : map.entrySet()) {
            System.out.println("K:" + m.getKey() + ", V:" + m.getValue());
            lists.add(m.getValue());
        }
        System.out.println(" - - - - - - - - - - - -");
        for (String str : strs) {
            System.out.println(str + "," + Collections.frequency(lists, str));
        }
    }


    public static List<String> toArrayByFileReader1(String name) {
        // 使用ArrayList来存储每行读取到的字符串
        List<String> arrayList = new ArrayList<>();
        try (
                FileReader fr = new FileReader(name);
                BufferedReader bf = new BufferedReader(fr);
        ) {
            String str;
            // 按行读取字符串
            while ((str = bf.readLine()) != null) {
                arrayList.add(str);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return arrayList;
    }

    public static long subStrToLong(String str, String start, String end) {
        int startIndex = str.indexOf(start);
        int endIndex = str.indexOf(end);
        String result = str.substring(startIndex + 2, endIndex).trim();
        return Long.parseLong(result);
    }

    public static double subStrToDouble(String str, String start, String end) {
        int startIndex = str.indexOf(start);
        int endIndex = str.indexOf(end);
        String result = str.substring(startIndex + 1, endIndex).trim();
        return Double.parseDouble(result);
    }

    public static String subStrAreacode(String str, String start, String end) {
        int startIndex = str.indexOf(start);
        String str1 = str.substring(startIndex + 2);
        int endIndex = str1.indexOf(end);
        String result = str.substring(startIndex + 2, startIndex + endIndex+2);
        return result;
    }
}
